/*----------------------------------------------------------------
 *  Author:        Zun Huang
 *  Written:       10/02/2014
 *  Last updated:  
 *  
 *  Description:Order contains order details for a specific order  
 *  record that a customer has made
 *
 *----------------------------------------------------------------*/

package JavaSource;
import java.io.Serializable;
import java.util.*;
/**
 *
 * @author huangzun
 */
public class Order implements Serializable,IdGenerable {
    
    //attributes for Order
    private static int globalId=6000;
    private int orderID;
    private int orderType; // 0 for delivery and 1 for pick up
    private Date orderDate;
    private Customer customer;
    private LinkedList<Dish> orderDishes;
    private String specialRec;
    private int orderStatus;
    private double totalPrice;

    //constructors
    public Order(Customer cust){
        this.orderID = generateId();
        orderDishes = new LinkedList<Dish>() ;
        this.orderType = orderType;
        this.orderDate = new Date();
        customer = cust;
    }
    public Order( int orderType, Date orderDate, Customer customer, LinkedList<Dish> orderDishes, String specialRec, int orderStatus,double totalPrice) {
        this.orderID = generateId();
        this.orderType = orderType;
        this.orderDate = orderDate;
        this.customer = customer;
        this.orderDishes =new LinkedList<Dish>() ;
        this.specialRec = specialRec;
        this.orderStatus = orderStatus;
        this.totalPrice = totalPrice;
    
    }
public void placeOrder(FoodOrderingSystem FOS)
{
    FOS.getOrderList().add(this);
}
    public void placeOrder(FoodOrderingSystem FOS, Member m)
    {
      placeOrder(FOS);
      //m.getOrderHistory().add(this);
    }
    public double getTotalPrice() {
        totalPrice = 0;
        for(Dish dish:orderDishes){
        totalPrice += dish.getPrice();
        }
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }
    
    //methods
    
    public static int getGlobalId() {
        return globalId;
    }

    public static void setGlobalId(int globalId) {
        Order.globalId = globalId;
    }
    
    public int getOrderID() {
        return orderID;
    }

    public void setOrderID(int orderID) {
        this.orderID = orderID;
    }

    public int getOrderType() {
        return orderType;
    }

    public void setOrderType(int orderType) {
        this.orderType = orderType;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public LinkedList<Dish> getOrderDishes() {
        return orderDishes;
    }

    public void setOrderDishes(LinkedList<Dish> orderDishes) {
        this.orderDishes = orderDishes;
    }

    public String getSpecialRec() {
        return specialRec;
    }

    public void setSpecialRec(String specialRec) {
        this.specialRec = specialRec;
    }
    public int getOrderStatusNum(){
    return 20*(this.orderStatus+1);
    
    }
    
    public String getOrderStatus() {
        String p1 = "Pending";
        String p2 = "In Process";
        String p3 = "Ready for Delivery";
        String p4 = "Ready for Pick-up";
        String p5 = "Completed";
        String p6 = "Deliver exception";
        String p = "";
        
        switch(this.orderStatus){
            case 0:
                p = p1;
                break;
            case 1: 
                p = p2;
                break;
            case 2:
                p = p3;
                break;
            case 3:
                p = p4;
                break;
            case 4:
                p = p5;
                break;
            case 5:
                p = p6;
                break;
        }
        return p;
    }//according to the orderStatus, get relevant Order Status

    
    public void setOrderStatus(String status) {
               switch(status){
            case "Pending":
                this.orderStatus = 0;
                break;
            case "In Process":
                this.orderStatus = 1;
                break;
            case "Ready for Delivery":
                this.orderStatus =2;
                break;
            case "Ready for Pick-up":
                this.orderStatus = 3;
                break;
            case "Completed":
                this.orderStatus = 4;
                break;
            case "Deliver exception":
                this.orderStatus = 5;
                break;
        } 
    }//set OrderStatus
    
       
    public boolean addDish(Dish dish){
        
        return true;
    }//add a new dish to an order
    
    public boolean modifyOrder(Order order)
    {
        this.customer = order.customer;
        this.orderDate = order.orderDate;
        this.orderDishes = order.orderDishes;
        this.orderID = order.orderID;
        this.orderStatus = order.orderStatus;
        this.orderType= order.orderType;
        this.specialRec = order.specialRec;
        return true;
    } //enable to modify order attributes if applicable

    @Override
    public int generateId() {
        return ++globalId;
    }
    
    

    
}
